package airthmetic.exercise.sort.cmp;


// 选择排序 未AC 超时
public class _912_排序数组_Select3 {
    public int[] sortArray(int[] nums) {
        if (nums == null || nums.length < 2) {
            return nums;
        }
        int n = nums.length;

        for (int i = 0; i < n; i++) {
            int minIndex = i;
            for (int j = i+1; j < n; j++) {
                if (nums[minIndex] > nums[j]) {
                    minIndex = j;
                }
            }
            swap(nums,minIndex,i);

        }
        return nums;

    }

    public void swap(int[] nums, int left, int right) {
        if (left == right) {
            return;
        }
        nums[left] ^= nums[right];
        nums[right] ^= nums[left];
        nums[left] ^= nums[right];
    }
}
